<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>修改角色</title>
    {% load static %}
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/css/oksub.css">
    <script type="text/javascript" src="/static/lib/loading/okLoading.js"></script>
    <script src="/static/lib/layui/layui.js"></script>

   <link type="text/css" rel="stylesheet" href="/static/css/metroStyle.css">
    <link type="text/css" rel="stylesheet" href="/static/css/treeSelectStyle.css">
    <script src="/static/js/jquery-1.11.2.min.js"></script>
    <script type="text/javascript" src="/static/js/jquery.ztree.all.js"></script>
    <script type="text/javascript" src="/static/js/treeSelect.2.0.js"></script>
    <script type="text/javascript" src="/static/js/xm-select.js"></script>
</head>
<body>
<div class="ok-body">
    <!--form表单-->
    <form class="layui-form layui-form-pane ok-form">
        <div class="layui-row layui-col-space10">
            <div class="layui-inline layui-col-md6">
                <label class="layui-form-label">角色代码<span style="color: red">*</span></label>
                <div class="layui-input-block">
                    <input type="text" name="role_code" id="role_code" placeholder="请输入角色代码！(唯一值)" autocomplete="off"
                           class="layui-input"
                           lay-verify="required">
                    <input type="text" name="id" id="id" class="layui-input" style="display: none">
                </div>
            </div>
            <div class="layui-inline layui-col-md6">
                <label class="layui-form-label">角色名称<span style="color: red">*</span></label>
                <div class="layui-input-block">
                    <input type="text" name="role_name" id="role_name" placeholder="请输入角色名称！" autocomplete="off"
                           class="layui-input"
                           lay-verify="required">
                </div>
            </div>
        </div>
        <div class="layui-row layui-col-space10" style="padding-top: 10px;">
            <div class="layui-inline layui-col-md6">
                <label class="layui-form-label">排序<span style="color: red">*</span></label>
                <div class="layui-input-block">
                    <input type="text" name="role_order" id="role_order" placeholder="请输入序号！(正整数)" autocomplete="off"
                           class="layui-input"
                           lay-verify="required">
                </div>
            </div>
            <div class="layui-inline layui-col-md6">
                <label class="layui-form-label">权限字符<span style="color: red">*</span></label>
                <div class="layui-input-block">
                    <input type="text" name="role_byte" id="role_byte" placeholder="请输入权限字符" autocomplete="off"
                           class="layui-input"
                           lay-verify="required">
                </div>
            </div>
        </div>
        <div class="layui-row layui-col-space10" style="padding-top: 10px;">
            <div class="layui-inline layui-col-md6">
                <label class="layui-form-label">权限集合<span style="color: red">*</span></label>
                <div class="layui-input-block" name="menu_role" id="menu_role">

                </div>
            </div>
            <div class="layui-inline layui-col-md6">
                <label class="layui-form-label">数据权限<span style="color: red">*</span></label>
                <div class="layui-input-block">
                    <select name="role_per" id="role_per" lay-verify="required">
                        <option value="">请选择</option>
                        <option value="01">全局数据</option>
                        <option value="02">本部门数据</option>
                        <option value="03">本部门及以下数据</option>
                        <option value="04">本人</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-form-text" style="padding-top: 10px;">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea name="remark_describe" id="remark_describe" placeholder="请输入备注内容"
                          class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="edit">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary" id="close">关闭</button>
            </div>
        </div>
    </form>
</div>
<!--js逻辑-->


<script type='text/javascript'>
    let data1;

    function child(d) {
        data1 = d;


    layui.use(["form", "okUtils", "form", "tree", "okLayer"], function () {
        let $ = layui.$;
        let form = layui.form;
        let okUtils = layui.okUtils;
        let okLayer = layui.okLayer;
        let tree = layui.tree;
        let util = layui.util;
        okLoading.close();
        $('#id').val(data1.id);
        $('#role_code').val(data1.role_code);
        $('#role_name').val(data1.role_name);
        $('#role_byte').val(data1.role_byte);
        $('#role_order').val(data1.role_order);
        $('#menu_role').val(data1.menus_id);
        $('#menus_id').val(data1.menus_id);
        $('#now_status').val(data1.now_status);
        $('#remark_describe').val(data1.remark_describe);
        $('#role_per').each(function () {
            $(this).children("option").each(function () {
                if(this.value===data1.role_per_id){
                    $(this).attr('selected','selected');
                }
            })
        });
        form.render();
        // 回显下拉框
         var demo3 = xmSelect.render({
                el: '#menu_role',
                model: {label: {type: 'text'}},
                initValue:data1.menus_id,
             prop:{
	                name:'tree_name',
                    value:'id',
                },
                tree: {
                    show: true,
                    strict: false,
                },
                height: 'auto',
                data() {
                    return []
                }
            });
            $.ajax({
                url: "{% url 'config:menus_list2' %}",
                type: "GET",
                success: function (ret) {
                    var node = ret.data;
                    demo3.update({
                        data: node,
                        autoRow: true,
                    })
                },
                error: function () {
                }
            });
        // 这里得把switch的状态弄对，不然，如果他创建就停用，数据就传不过去了
        form.on("submit(edit)", function (data) {
            okUtils.ajax("/config/roles_edit/" + data.field.id, "post",data.field, true).done(function (response) {
                okLayer.greenTickMsg(response.msg, function () {
                    parent.layui.table.reload('tableId');
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                });
            }).fail(function (error) {
                // 这里已经有提示了
            });
            return false;
        });
        $("#close").click(function () {
            let index = parent.layer.getFrameIndex(window.name); //获取当前窗口的name
            parent.layui.table.reload('tableId');
            parent.layer.close(index);
        });
    })};
</script>
</body>
</html>
